package sw.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sw.dao.UserDao;
import sw.entity.User;
import sw.model.UserModel;
import sw.service.IUserService;

@Service
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserDao userDao;
	
	
	@Override
	public Integer Login(String name, String password) {
		 List<User> userList = userDao.findByNameAndPassword(name, password);
		 if(null == userList || userList.size()==0)	
			 return null;
		 return userList.get(0).getId();
	}


	@Override
	public List<UserModel> findAllUsers() {
		List<User> userList = (List<User>) userDao.findAll();
		List<UserModel> modelList = new ArrayList<UserModel>();
		if(null !=userList){
			for(User user : userList){
				UserModel model = new UserModel();
				model.setId(user.getId());
				model.setName(user.getName());
				modelList.add(model);
			}
			
		}
		return modelList;
	}

}
